var elNewPassword            = document.getElementById('newPassword'),
    elNewPasswordMsg         = document.getElementById('newPasswordMsg'),
    elRepeatNewPassword      = document.getElementById('repeatNewPassword'),
    elRepeatNewPasswordMsg   = document.getElementById('repeatNewPasswordMsg');

var newPasswordFlag = 0;

function checkNewPassword(newPassword){
    if(newPassword === null || newPassword === '' || newPassword.length === 0){
        elNewPasswordMsg.innerHTML = "<font color='orange'>请输入密码</font>";
        newPasswordFlag = 0;
    } else if (newPassword.length < 6){
        elNewPasswordMsg.innerHTML = "<font color='red'>密码长度应大于等于6位</font>";
        newPasswordFlag = 0;
    }else{
        elNewPasswordMsg.innerHTML = "<font color='green'>密码合法</font>";
        newPasswordFlag = 1;
    }
}

function checkRepeatNewPassword(newPassword,repeatNewPassword){
    if(repeatNewPassword === null || repeatNewPassword === '' || repeatNewPassword.length === 0){
        elRepeatNewPasswordMsg.innerHTML = "<font color='orange'>请确认密码</font>";
    } else if(repeatNewPassword === newPassword && newPasswordFlag ){
        elRepeatNewPasswordMsg.innerHTML = "<font color='green'>密码合法</font>";
    } else{
        elRepeatNewPasswordMsg.innerHTML = "<font color='red'>新密码有误</font>";
    }
}

elNewPassword.addEventListener('blur', function (){
    var newPassword = elNewPassword.value.trim();
    checkNewPassword(newPassword);
})

elRepeatNewPassword.addEventListener('blur', function (){
    var repeatNewPassword = elRepeatNewPassword.value.trim();
    var newPassword = elNewPassword.value.trim();
    checkRepeatNewPassword(newPassword,repeatNewPassword);
})